package com.itheima.test7;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author:gy
 * @Date: 2025/09/04 10:51
 * @Description:
 */
public class ServerDemo {
    public static void main(String[] args) throws Exception {
        //2.接收端接受客户端发送的消息
        ServerSocket ss = new ServerSocket(10086);
        //监听客户的Socket
        Socket socket = ss.accept();
        //获得输入流
        InputStream is = socket.getInputStream();
        int b;
        while ((b = is.read()) != -1) {
            System.out.print((char) b);
        }
        //3.给出反馈 给客户端一个反馈  告诉他我们接受到了消息
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        //OutputStream os = socket.getOutputStream();
        bw.write("你谁啊");
        bw.newLine();
        bw.flush();
        socket.close();
        ss.close();
    }

}
